<!--
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 14:41:20
 * @LastEditTime: 2023-10-30 13:00:32
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description:   :gridOps="gridOptions" 
-->
<template>
  <sc-VxeTable
    ref="xGrid1"
    :gridEvts="gridEvents"
    :tablecode="'purchase_order_dye'"
    :url="this.$API.purchase.order.list"
    :params="{ type: 2 }"
  >
  </sc-VxeTable>

  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSuccess"
    @closed="dialog.save = false"
  >
  </save-dialog>

  <ReciveDialog
    v-if="dialog.recive"
    ref="reciveDialog"
    @success="handleSuccess"
    @closed="dialog.recive = false"
  >
  </ReciveDialog>
</template>
<script>
import SaveDialog from "./save";
import ReciveDialog from "./ReciveDialog";
export default {
  components: {
    SaveDialog,
    ReciveDialog,
  },
  name: "purchase_order_dye",
  data() {
    return {
      dialog: {
        save: false,
        recive: false,
      },
      gridEvents: {
        cellDblclick: ({ row }) => {
          this.edit(row);
        },
        add: () => {
          // this.$router.push({ path: "./order/save" });
          this.openSave();
        },
        edit: ({ button }) => {
          this.edit(button.selectRecords[0]);
        },
        recive: ({ button }) => {
          this.recive(button.selectRecords);
        },
      },
    };
  },
  methods: {
    openSave: function () {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open().setType(2);
      });
    },

    handleSuccess() {
      this.$refs.xGrid1.refresh();
    },
    recive(data) {
      if (data[0]["status_id"] == 0) {
        return this.$message.error("订单必须审核！");
      }
      this.dialog.recive = true;

      this.$nextTick(() => {
        this.$refs.reciveDialog.setData(data[0]);
        this.$refs.reciveDialog.open("edit");
      });
    },
    edit(item) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(item);
      });
    },
  },
};
</script>
